package xyz.heyaoshare.config.xss;

import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * XSS过滤器
 * @author YueHe
 * @version 0.0.1
 * @since 2025/6/25 上午11:51
 */
@Slf4j
public class XSSFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {
        // 初始化逻辑
        log.info("初始化XSSFilter...");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        // 获取请求路径
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        String requestURI = httpRequest.getRequestURI();

        log.info("XSSFilter: 处理请求: {}", requestURI);
        XSSRequestWrapper wrappedRequest = new XSSRequestWrapper(httpRequest);
        chain.doFilter(wrappedRequest, response);
    }

    @Override
    public void destroy() {
        // 销毁逻辑
        log.info("销毁XSSFilter");
    }

}